home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 16 / AMIGAplus Sonderheft 16 (1998)(ICP)(DE)[!].iso / pd / anwendungen / rtgmaster_dev / demos / ping / ping.c < prev   
C/C++ Source or Header  |  1996-07-04  |  8KB  |  278 lines

  1. /*
  2.  
  3.         RTG Library Usage Demo - Bouncing Truecolor ball
  4.  
  5. */
  6. //* "Includes"
  7.  
  8.  
  9. /* Generic "Include Everything"-type file */
  10. #include <stdlib.h>
  11. #include <proto/utility.h>
  12. #include <proto/exec.h>
  13. #include <clib/rtgmaster_protos.h>
  14. #include <clib/exec_protos.h>
  15. #include <clib/utility_protos.h>
  16. #include <pragmas/rtgmaster_pragmas.h>
  17. #include <pragmas/exec_pragmas.h>
  18. #include <pragmas/utility_pragmas.h>
  19. #include <exec/memory.h>
  20. #include <utility/tagitem.h>
  21. #include <rtgmaster/rtgmaster.h>
  22. #include <rtgmaster/rtgsublibs.h>
  23. #include <proto/rtgmaster.h>
  24. #include <string.h>
  25. #include <stdio.h>
  26. #include <clib/dos_protos.h>
  27.  
  28.  
  29. //*
  30. //* "Globals"
  31. struct RtgScreen *RtgScreen;
  32. struct ScreenReq *sr;
  33. struct RTGMasterBase *RTGMasterBase;
  34. struct Library *UtilityBase, *IntuitionBase;
  35. struct Library *GfxBase;
  36. extern struct Library *DOSBase;
  37. struct TagItem rtag[] = {
  38.     smr_ChunkySupport,  -1,
  39.     smr_PlanarSupport,  -1,
  40.     smr_PrefsFileName,  (ULONG)"PingRtg.prefs",
  41.     smr_Buffers,        2,
  42.     TAG_DONE,           NULL
  43. };
  44.  
  45. struct TagItem gtag[] = {
  46.     grd_BytesPerRow,    0,
  47.     grd_Width,          0,
  48.     grd_Height,         0,
  49.     grd_Depth,          0,
  50.     grd_PixelLayout,    0,
  51.     grd_ColorSpace,     0,
  52.     grd_PlaneSize,      0,
  53.     grd_BusSystem,      0,
  54.     TAG_DONE,           0
  55. };
  56.  
  57. struct TagItem tacks[] = {
  58.     rtg_Buffers,    2,
  59.     TAG_DONE,       0
  60. };
  61.  
  62. BOOL Planar;
  63. UBYTE *cbuf=NULL;
  64. ULONG width;
  65. UBYTE *sadr, *sadr2;
  66. ULONG cmap[800];
  67. #define CBUF 76800
  68.  
  69. /*
  70.  * This is done using an ugly direct hardware hit
  71.  * Should be an input handler or similar in future versions/real-life
  72.  * applications!
  73.  */
  74. extern int MouseButton(void);
  75. UBYTE *image;
  76.  
  77. //*
  78. //* "fail"
  79. void fail(void) {
  80.     if (RtgScreen) CloseRtgScreen(RtgScreen);
  81.     if (RTGMasterBase) CloseLibrary((struct Library *)RTGMasterBase);
  82.     if (UtilityBase) CloseLibrary(UtilityBase);
  83.     if (cbuf) FreeVec(cbuf);
  84.     exit(0L);
  85. }
  86. //*
  87. //* "LoadImage"
  88. BOOL LoadImage(void) {
  89.     FILE *f;
  90.  
  91.     image=AllocVec(2976,MEMF_ANY);
  92.     if (!image) return FALSE;
  93.  
  94.     f=fopen("Kugel.raw", "r");
  95.     fread(image, 1,2976,f);
  96.     fclose(f);
  97.  
  98. }
  99. //*
  100. //* "main"
  101. void main(int argc, char **argv) {
  102.    /*
  103.     * Since this is a demo, I don't check anything at all
  104.     * and simply assume that every open went ok... 8-)
  105.     */
  106.     int a,b;
  107.     int img;
  108.     struct TagItem *tag;
  109.     UBYTE rr, rg, rb;
  110.     ULONG size;
  111.     LONG spx, spy;
  112.     LONG sx,sy;
  113.     LONG mx, my;
  114.  
  115.  
  116.     RTGMasterBase = (struct RTGMasterBase *)OpenLibrary((STRPTR)"rtgmaster.library", 0);
  117.     UtilityBase = OpenLibrary((STRPTR)"utility.library", 37L);
  118.     IntuitionBase = OpenLibrary("intuition.library", 37L);
  119.     GfxBase = OpenLibrary("graphics.library", 37L);
  120.  
  121.     sr = RtgScreenModeReq(rtag);
  122.  
  123.     if (sr==NULL) fail();
  124.  
  125.     RtgScreen = OpenRtgScreen(sr, tacks);
  126.  
  127.     GetRtgScreenData(RtgScreen, gtag);
  128.  
  129.     tag=FindTagItem(grd_BytesPerRow, gtag);
  130.     size = tag->ti_Data;
  131.  
  132.     tag=FindTagItem(grd_Width, gtag);
  133.     width = tag->ti_Data;
  134.  
  135.     tag=FindTagItem(grd_Depth, gtag);
  136.     if (tag->ti_Data < 15) {
  137.         printf("Screenmode not supported\n");
  138.         fail();
  139.     }
  140.  
  141.     tag=FindTagItem(grd_PixelLayout, gtag);
  142.     printf("Screen pixel layout is ");
  143.     switch(tag->ti_Data) {
  144.         case grd_PLANAR:        printf("planar\n"); break;
  145.         case grd_PLANATI:       printf("interleaved planar\n"); break;
  146.         case grd_CHUNKY:        printf("8-Bit Z-Ordered (chunky)\n"); break;
  147.         case grd_HICOL15:       printf("15-Bit Chunky (2 Byte/pixel)\n"); break;
  148.         case grd_HICOL16:       printf("16-Bit Chunky (2 Byte/pixel)\n"); break;
  149.         case grd_TRUECOL24:     printf("24-Bit Chunky (3 Byte/pixel)\n"); break;
  150.         case grd_TRUECOL24P:    printf("24-Bit Chunky (3 Byteplanes/pixel)\n"); break;
  151.         case grd_TRUECOL32:     printf("24-Bit Chunky (4 Bytes/pixel)\n"); break;
  152.         case grd_GRAFFITI:      printf("Graffiti 8 bit\n"); break;
  153.         case grd_TRUECOL32B:    printf("24-Bit Chunky (4 Bytes/pixel)\n"); break;
  154.         default:                printf("unknown (%d)\n", tag->ti_Data); break;
  155.     }
  156.  
  157.     tag=FindTagItem(grd_ColorSpace, gtag);
  158.     if (tag->ti_Data) {
  159.         printf("Color space is ");
  160.         switch(tag->ti_Data) {
  161.             case grd_Palette:   printf("CLUT-Based\n"); break;
  162.             case grd_RGB:       printf("RGB (low-endian RGB)\n"); break;
  163.             case grd_BGR:       printf("BGR (high-endian RGB)\n"); break;
  164.             default:            printf("unknown (%d)\n", tag->ti_Data); break;
  165.         }
  166.     }
  167.  
  168.     tag=FindTagItem(grd_BusSystem, gtag);
  169.     if (tag->ti_Data) {
  170.         printf("Graphics card bus is ");
  171.         switch(tag->ti_Data) {
  172.             case grd_Z3:        printf("Zorro III\n"); break;
  173.             case grd_Z2:        printf("Zorro II\n"); break;
  174.             case grd_Custom:    printf("default custom chips\n"); break;
  175.             case grd_RGBPort:   printf("conneted to the RGB Port\n"); break;
  176.             case grd_GVP:       printf("GVP Special Bus (EGS110)\n"); break;
  177.             case grd_DDirect:   printf("DracCo® Direct\n"); break;
  178.             default:            printf("an unknown bus system\n"); break;
  179.         }
  180.     }
  181.  
  182.     if (tag->ti_Data == grd_PLANAR) Planar = TRUE;
  183.     else Planar = FALSE;
  184.  
  185.  
  186.     mx=FindTagItem(grd_Width,  gtag)->ti_Data - 34;
  187.     my=FindTagItem(grd_Height, gtag)->ti_Data - 34;
  188.  
  189.     printf("Screen is %ld x %ld x %ld\n", gtag[1].ti_Data, gtag[2].ti_Data, gtag[3].ti_Data);
  190.     printf("It has %ld bytes per row\n", size);
  191.  
  192.  
  193.     if (Planar == TRUE) {
  194.         cbuf = AllocVec(CBUF, MEMF_CLEAR|MEMF_FAST);
  195.         if (cbuf==NULL) {
  196.             cbuf=AllocVec(CBUF, MEMF_CLEAR);
  197.             if (cbuf==NULL) {
  198.                 printf("Out of memory *SIGH*\n");
  199.                 fail();
  200.             }
  201.         }
  202.     }
  203.  
  204.     LoadImage();
  205.  
  206.     if (RtgScreen) {
  207.         LockRtgScreen(RtgScreen);
  208.         sadr = (UBYTE *)GetBufAdr(RtgScreen,0);
  209.         sadr2 = (UBYTE *)GetBufAdr(RtgScreen,1);
  210.  
  211.         //RtgBltClear(RtgScreen,0,0,0,gtag[1].ti_Data,gtag[2].ti_Data);
  212.         //RtgBltClear(RtgScreen,1,0,0,gtag[1].ti_Data,gtag[2].ti_Data);
  213.  
  214.  
  215.         FillRtgRectRGB(RtgScreen, sadr, 0x00000000,
  216.             0,0, gtag[1].ti_Data, gtag[2].ti_Data);
  217.         SwitchScreens(RtgScreen, 1);
  218.         FillRtgRectRGB(RtgScreen, sadr2, 0x0000000,
  219.             0,0, gtag[1].ti_Data, gtag[2].ti_Data);
  220.  
  221.         Delay(50L);
  222.  
  223.         img=0;
  224.         for (a=0; a<31; a++) {
  225.             for (b=0; b<32; b++) {
  226.                 rr=image[img];
  227.                 rg=image[img+1];
  228.                 rb=image[img+2]; img+=3;
  229.                 WriteRtgPixelRGB(RtgScreen, sadr2, 20+(ULONG)b,20+(ULONG)a,
  230.                     rb|rg<<8|rr<<16);
  231.             }
  232.         }
  233.  
  234.         SwitchScreens(RtgScreen, 0);
  235.  
  236.         spx=2; spy=3;
  237.         sx=18; sy=18;
  238.  
  239.         Forbid();
  240.         while(MouseButton()==0) {
  241.             sx+=spx; sy+=spy;
  242.             if (sx>mx) {
  243.                 sx=mx;
  244.                 spx=-spx;
  245.             } else if (sx<3) {
  246.                 sx=3;
  247.                 spx=-spx;
  248.             }
  249.             if (sy>my) {
  250.                 sy=my;
  251.                 spy=-spy;
  252.             } else if (sy<3) {
  253.                 sy=3;
  254.                 spy=-spy;
  255.             }
  256.             RtgWaitTOF(RtgScreen);
  257.             RtgBlit(RtgScreen, 1, 0,
  258.                 18,18,
  259.                 (ULONG)sx, (ULONG)sy,
  260.                 36, 36, 0xC0);
  261.             WaitRtgBlit(RtgScreen);
  262.  
  263.         }
  264.         Permit();
  265.         UnlockRtgScreen(RtgScreen);
  266.         CloseRtgScreen(RtgScreen);
  267.     }
  268.  
  269.     FreeVec(image);
  270.  
  271.     CloseLibrary(GfxBase);
  272.     CloseLibrary((struct Library *)RTGMasterBase);
  273.     CloseLibrary(UtilityBase);
  274.     CloseLibrary(IntuitionBase);
  275. }
  276. //*
  277.  
  278.